package com.atguigu.srb.sms.controller;

import com.atguigu.srb.base.exception.SrbBussinessException;
import com.atguigu.srb.base.result.R;
import com.atguigu.srb.base.result.ResponseEnum;
import com.atguigu.srb.sms.feign.RpcClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/sms")
public class TestController {
    @Resource
    RpcClient rpcClient;
    @GetMapping("/test1")
    public R test1(){
       //远程调用core的接口
        R r = rpcClient.test1(); //如果远程调用成功 接收的返回值是core服务返回的
        //如果远程调用失败，兜底方案处理成功返回的是兜底方法的结果
        System.out.println("获取到的core服务的响应:" + r);
        return r;
    }
    @GetMapping("/test2")
    public R test2(){
        //远程调用core的接口
        R r = rpcClient.test2("9527");
        System.out.println("获取到的core服务的响应:" + r);
        return R.ok();
    }
    @GetMapping("/test3")
    public R test3(){
        //远程调用core的接口
        R r = rpcClient.test3("taotao","pangju");
        System.out.println("获取到的core服务的响应:" + r);
        return R.ok();
    }
    @GetMapping("/test4")
    public R test4(){
        //远程调用core的接口
        R r = rpcClient.test4(new SrbBussinessException(ResponseEnum.CODE_ERROR));
        System.out.println("获取到的core服务的响应:" + r);
        return R.ok();
    }
    @GetMapping("/test5")
    public R test5(){
        //远程调用core的接口
        R r = rpcClient.test5(new SrbBussinessException(ResponseEnum.CODE_ERROR));
        System.out.println("获取到的core服务的响应:" + r);
        return R.ok();
    }
}
